<?php


namespace app\controller\api;


use app\common\service\face\FaceDevice;
use app\common\service\redis\PoolRedis;
use app\model\AdminStaffIcCard;
use app\model\AdminStudentDormitory;
use think\facade\Log;
use think\Response;

class Test extends Base
{
    public function run() : Response {
//        $where = [
//            'is_delete' => 0,
//            'school_id' => 41
//        ];
//        $list = (new AdminStudentDormitory())->where($where)->select();
//        foreach ($list as $student_dormitory) {
//            AdminStudentDormitory::resetPool($student_dormitory);
//        }
//        return $this->buildSuccess([]);

//        $stu_sub_query = AdminStudentDormitory
//            ::where('is_delete', 0)
//            ->field('id,name student_dormitory_name,uuid,door_type');
//        $stu_sub_query = $stu_sub_query->buildSql();
//        $result = AdminStaffIcCard::alias('card')
//            ->join([$stu_sub_query => 'sd'], 'sd.id=card.student_dormitory_id')
//            ->where([
//                'card.is_delete' => 0,
//                'card.school_id' => 41
//            ])
//            ->with(['staff','dormitory'])
//            ->hidden(['school_id','create_time','update_time','is_delete'])
//            ->select()->toArray();
//
//        $resultAAA = [];
//        $redis = PoolRedis::instance();
//
//        foreach ($result as $key => $item) {
//            $staff = $item['staff'];
//            $result[$key]['sim_uid'] = $staff['sim_card'];
//            if (($result[$key]['door_type']=="KD"||$result[$key]['door_type']=="KD254")
//                && empty($result[$key]['ic_card']) && empty($result[$key]['sim_uid'])) {
//
//                $distributionKey = AdminStudentDormitory::NO_KEY."41:".$result[$key]['student_dormitory_id'];
//                $noKey = $distributionKey.':no';
//                $no = $redis->hGet($noKey, $result[$key]['staff_id']);
//
//                if ($no){
//                    $redis->hDel($noKey, $result[$key]['staff_id']);
//
//                    $poolKey = $distributionKey.':pool';
//                    $redis->lPush($poolKey, $no);
//                    $resultAAA[] = ("撤回编号 ".$result[$key]['student_dormitory_name'].' 学生ID '.$result[$key]['staff_id'].' 编号 '.$no);
//                } else {
//                    // 0的编号
//                    if ($no!='') {
//                        Log::error("编号 ".$no);
//                        $redis->hDel($noKey, $result[$key]['staff_id']);
//                    }
//                }
//
//
//            }else{
//                unset($result[$key]);
//            }
//        }
//        return $this->buildSuccess($resultAAA);


        return $this->buildSuccess([FaceDevice::openDoor('2465768')]);
    }
}